1 package org.smartcomps.twister.engine.core.dynamic;
2
3 import junit.framework.TestCase;
4 import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
5 import net.sf.hibernate.cfg.Configuration;
6 import org.smartcomps.twister.common.transaction.TransactionManager;
7 import org.smartcomps.twister.common.lifecycle.LifecycleManager;
8 import org.smartcomps.twister.engine.core.definition.TestProcess;
9 import org.smartcomps.twister.engine.core.definition.TestSequence;
10 import org.smartcomps.twister.engine.priv.core.definition.Invoke;
11 import org.smartcomps.twister.engine.priv.core.dynamic.ProcessInstance;
12 import org.smartcomps.twister.engine.priv.core.dynamic.ExecutionContext;
13 import org.smartcomps.twister.engine.priv.core.dynamic.ProcessInstanceFactory;
14 import org.smartcomps.twister.engine.priv.core.dynamic.SequenceEC;
15 import org.smartcomps.twister.engine.priv.core.dynamic.InvokeEC;
16
17 import java.util.Map;
18 import java.util.HashMap;
19
20 /***
21 * Tests sequence execution
22 */
23 public class TestSequenceEC extends TestCase {
24
25 private TestProcess testProcess = new TestProcess();
26 private TestSequence testSequence = new TestSequence();
27
28 protected void setUp() throws Exception {
29 LifecycleManager.getLifecycleManager().createResources();
30 LifecycleManager.getLifecycleManager().startResources();
31
32 SchemaExport schemaExport = new SchemaExport(new Configuration().configure());
33 schemaExport.create(true, true);
34
35 TransactionManager.beginTransaction();
36 testProcess.testCreateWithCorrelation();
37 testSequence.testCreate();
38 TransactionManager.commitTransaction();
39 TransactionManager.beginTransaction();
40
41 }
42
43 protected void tearDown() throws Exception {
44 TransactionManager.commitTransaction();
45
46 LifecycleManager.getLifecycleManager().stopResources();
47 LifecycleManager.getLifecycleManager().destroyResources();
48 }
49
50 public void testExecute() throws Exception {
51 Map corrProp = new HashMap();
52 corrProp.put(TestProcess.CORRELATION_PROP1, "2578");
53 corrProp.put(TestProcess.CORRELATION_PROP2, "12");
54
55 ((Invoke)TestSequence.testSequence.getActivities().get(0)).execute(TestProcess.CORRELATION_NAME, corrProp);
56
57 TransactionManager.commitTransaction();
58 TransactionManager.beginTransaction();
59
60 try {
61 ProcessInstance createdInstance = ProcessInstanceFactory.findInstanceByCorrelation(TestProcess.CORRELATION_NAME, corrProp);
62 assertEquals("Process is not completed after execution ended", ProcessInstance.COMPLETED, createdInstance.getStatus());
63 assertTrue("Instance child execution context is not a sequence", createdInstance.getChildExecutionContext() instanceof SequenceEC);
64 assertEquals("Sequence is not completed after execution ended", ExecutionContext.COMPLETED, createdInstance.getChildExecutionContext().getStatus());
65
66 assertTrue("Sequence first child execution context is not an invoke", ((SequenceEC)createdInstance.getChildExecutionContext()).getExecutionContexts().get(0) instanceof InvokeEC);
67 assertEquals("First invoke is not completed after execution ended", ExecutionContext.COMPLETED, ((InvokeEC)((SequenceEC)createdInstance.getChildExecutionContext()).getExecutionContexts().get(0)).getStatus());
68 assertTrue("Sequence second child execution context is not an invoke", ((SequenceEC)createdInstance.getChildExecutionContext()).getExecutionContexts().get(1) instanceof InvokeEC);
69 assertEquals("Second invoke is not completed after execution ended", ExecutionContext.COMPLETED, ((InvokeEC)((SequenceEC)createdInstance.getChildExecutionContext()).getExecutionContexts().get(1)).getStatus());
70 assertTrue("Sequence third child execution context is not an invoke", ((SequenceEC)createdInstance.getChildExecutionContext()).getExecutionContexts().get(2) instanceof InvokeEC);
71 assertEquals("Third invoke is not completed after execution ended", ExecutionContext.COMPLETED, ((InvokeEC)((SequenceEC)createdInstance.getChildExecutionContext()).getExecutionContexts().get(2)).getStatus());
72 } catch (Exception e) {
73 e.printStackTrace();
74 }
75 }
76
77 }
This page was automatically generated by Maven